package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.DeptFile;
import com.ruoyi.system.mapper.DeptFileMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DeptFileUserDownloadMapper;
import com.ruoyi.system.domain.DeptFileUserDownload;
import com.ruoyi.system.service.IDeptFileUserDownloadService;

/**
 * 文件下载Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-17
 */
@Service
public class DeptFileUserDownloadServiceImpl implements IDeptFileUserDownloadService
{
    @Autowired
    private DeptFileUserDownloadMapper deptFileUserDownloadMapper;
    @Autowired
    private DeptFileMapper deptFileMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询文件下载列表
     *
     * @param deptFile 文件下载
     * @return 文件下载
     */
    @Override
    public List<DeptFile> selectDeptFileUserDownloadList(DeptFile deptFile)
    {
        List<DeptFile> resultList = deptFileUserDownloadMapper.selectDeptFileUserDownloadList(deptFile);
        return resultList;
    }

    /**
     * 删除
     *
     * @param fileId 部门文件主键
     * @return 结果
     */
    @Override
    public int deleteDownloadFile(Long fileId){
        List<DeptFile> deptFiles = deptFileMapper.selectChildrenDeptFileByFileId(fileId);
        for(DeptFile file :deptFiles ){
            deptFileUserDownloadMapper.deleteDeptFileUserDownloadById(file.getFileId());
        }
        return deptFileUserDownloadMapper.deleteDeptFileUserDownloadById(fileId);
    }
}
